﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using CvModel;

namespace LAB3_Cv
{
    public partial class RegisterUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ButtonRegister_Click(object sender, EventArgs e)
        {
            try
            {
                ApplicantDB.CreateApplicant(new Applicant
                {
                    FirstName = TextBoxFirstName.Text,
                    LastName = TextBoxLastName.Text,
                    Address = TextBoxAddress.Text,
                    City = TextBoxCity.Text,
                    Zip = TextBoxZip.Text,
                    Email = TextBoxEmail.Text,
                    Phone = TextBoxPhone.Text,
                    PersonNumber = TextBoxSocialSecurity.Text,
                    Password = TextBoxPassword.Text,
                    RegistredCv = true
                });
                int applicantId = ApplicantDB.GetApplicantId(TextBoxSocialSecurity.Text, TextBoxPassword.Text);

                Cv cv = new Cv { Miscellaneous = "", Interests = "", PersonalQualities = "", IsDeleted = false, ApplicantApplicantId = applicantId };
                CvDB.CreateCV(cv);
                int cvId = CvDB.GetCvIdWithApplicantId(applicantId);

                CvDB.CreateMerit(new Merits { CvCvId = cvId, Desription = "", Ranking = CvModel.RankingMerits.Mellan });
                CvDB.CreateEducations(new Educations { CvCvId = cvId, Desription = "" });
                CvDB.CreateExperiences(new Experiences { CvCvId = cvId, Description = "", Ranking = CvModel.Ranking.Mellan });


                UserRegistered();
                

            }
            catch (Exception)
            {
                
                throw;
            }
            

        }
        private void UserRegistered()
        {
            LabelRegistered.Visible = true;
            TextBoxFirstName.Text = "";
            TextBoxLastName.Text = "";
            TextBoxAddress.Text = "";
            TextBoxCity.Text = "";
            TextBoxZip.Text = "";
            TextBoxEmail.Text = "";
            TextBoxPhone.Text = "";
            TextBoxSocialSecurity.Text = "";
            TextBoxPassword.Text = "";
        }

    }
}